package edu.taru.controller;

import edu.taru.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.LocalDateTime;

@Controller
public class ExcelController {
    private ExcelService exService;
    //注入上传文件的路径
    @Resource(name = "uploadFileVirtualPath")
    String uploadFileVirtualPath;

    @Autowired
    public ExcelController(ExcelService exService){
        this.exService = exService;
    }
    @RequestMapping(value = "/excel/download", method = {RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> download() throws IOException {
        //字节数组输出流
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        //调用服务层导出
        return exService.exportDeptExcel(out);
    }
}
